package com.longteng.testng.param;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * Created by sky on 15-12-23
 */
public class Row {


    private Map<String,Pair> pairMap = Maps.newHashMap();

    public void setPairs(List<Pair> pairs){
        if(pairs!=null&&pairs.size()>0){
            pairs.forEach(it -> pairMap.put(it.getKey(),it));
        }
    }


    public void addPair(Pair pair){
        this.pairMap.put(pair.getKey(),pair);
    }

    public List<Pair> getPairs(){
        Collection<Pair> collection = this.pairMap.values();
        if(collection.size()==0){
            return Lists.newArrayList();
        }else{
            return Lists.newArrayList(this.pairMap.values());
        }
    }

    public Optional<Pair> get(String key){
        return Optional.of(pairMap.get(key));
    }

}
